export function generateRandomData(count) {
    const data = [];
    for (let i = 0; i < count; i++) {
        const item = {
            w: Math.floor(Math.random() * 1000), // 随机生成0到999之间的整数
            h: Math.floor(Math.random() * 1000)  // 随机生成0到999之间的整数
        };
        data.push(item);
    }

    return data;
}

/**
 * 加载所有图片并设置对应的宽高
 * @param list
 */
export async function setImageSize(list) {
    const total = list.length;
    let count = 0;
    return new Promise(function (resolve) {
        function loadImage(item) {
            const img = new Image();
            img.src = item.photo;
            function complete(target) {
                count++;
                item.width = img.width;
                item.height = img.height;
                if (count >= total) {
                    resolve(list);
                }
            }
            img.onload = () => complete(img);
            img.onerror = function () {
                item.photo = defaultPic.data;
                complete(defaultPic);
            };
        }
        for (let i = 0; i < total; i++) {
            loadImage(list[i]);
        }
    });
}